import java.util.*;

public class 相差不超过k的最多数 {
    /*
    https://www.nowcoder.com/practice/562630ca90ac40ce89443c91060574c6?tpId=308&tqId=40490&ru=/exam/oj
    很明显的滑一下
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] arr = new int[n];
        for(int i = 0;i < n;i++){
            arr[i] = in.nextInt();
        }
        //排序
        Arrays.sort(arr);
        // 1 2 2 3 5
        int left = 0;
        int ret = -1;
        for(int right = 0;right < n;right++){
            //判断一下
            while(Math.abs(arr[right] - arr[left]) > k){
                left++;
            }
            //记录
            ret = Math.max(ret,right - left + 1);
        }
        System.out.println(ret);
    }
}
